#include "visionserver.h"
#include <QImage>
#include "cameraDevice/silicoolcamerafactory.h"

VisionServer::VisionServer(QObject *parent) : SilicoolVisionSimpleSource ()
{

}

int VisionServer::getImage(QString cameraName)
{
    qInfo("Vision server get image");
    QImage image;
    image.load("test.jpg");
    //memcpy(m_content.data(), image.bits(), image.byteCount());
    this->m_content = QByteArray::fromRawData((char*)image.bits(), image.byteCount());
    qInfo("content length: %d", m_content.count());
    return 1;
}

QByteArray VisionServer::getImageEx(QString cameraName)
{
    qDebug() << "getImage" << cameraName;
    bool ret = false;
    QImage img = SilicoolcameraFactory::instance().getImage(cameraName, ret);
    setImgFormat(img.format());
    setWidth(img.width());
    setHeight(img.height());
    QByteArray buffer((char *)img.bits(), img.byteCount());
    return buffer;
}
